VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "ConnectClass"
Attribute VB_Creatable = True
Attribute VB_Exposed = True
Attribute VB_Description = "Toolbar Saver"
Option Explicit

Private VBInstance As Object
'___VBIDE menu objects
Dim tbWizMenu As VBIDE.SubMenu
Dim tbWizLoadItem As VBIDE.MenuLine
Dim tbWizSaveItem As VBIDE.MenuLine

'___toolbar wiz menu item objects to receive AfterClick events
Dim tbWizLoadItemEventHandler As New tbMenuItem
Dim tbWizSaveItemEventHandler As New tbMenuItem
'___vars to track connection to AfterClick events
Dim tbWizLoadItemConnectID As Long
Dim tbWizSaveItemConnectID As Long


Public Sub ConnectAddIn(NewVBInstance As VBIDE.Application)

    On Error GoTo errConnectAddIn
    Set VBInstance = NewVBInstance
    Set gobjIDEAppInst = NewVBInstance
    
'___Add custom items to Add-In menu
    Set tbWizMenu = VBInstance.AddInMenu.MenuItems.AddMenu("&Toolbar Wizard")
    With tbWizMenu.MenuItems
        Set tbWizLoadItem = .Add("&Save current toolbar...")
        Set tbWizSaveItem = .Add("&Load toolbar...")
    End With
    
'___identify menuLine event handlers
    tbWizLoadItemConnectID = tbWizLoadItem.ConnectEvents(tbWizLoadItemEventHandler)
    tbWizSaveItemConnectID = tbWizSaveItem.ConnectEvents(tbWizSaveItemEventHandler)
'___tell event handlers what events they are to handle
    tbWizLoadItemEventHandler.Operation = opSave
    tbWizSaveItemEventHandler.Operation = opLoad
    Set tbWizLoadItemEventHandler.VBInstance = VBInstance
    Set tbWizSaveItemEventHandler.VBInstance = VBInstance
    Exit Sub

errConnectAddIn:
    MsgBox ("An error occured while connecting the tbWiz Add-in.  " & Error$)
    Exit Sub

End Sub

Public Sub DisconnectAddIn(Mode As Integer)

    On Error GoTo errDisconnectAddIn
'___disconnect event handlers
    tbWizLoadItem.DisconnectEvents tbWizLoadItemConnectID
    tbWizSaveItem.DisconnectEvents tbWizSaveItemConnectID

'___remove custom menu itesm
    VBInstance.AddInMenu.MenuItems.Remove tbWizMenu
    Set gobjIDEAppInst = Nothing

    Exit Sub

errDisconnectAddIn:
    Alert "An error occured while disconnecting the tbWiz Add-In.  " & Error$
    Exit Sub

End Sub

